package ee.rsi2m.goproject;


import ee.rsi2m.goproject.service.SurfaceViewThread;
import ee.rsi2m.goproject.view.GoBoardView;
import ee.rsi2m.goproject.view.GoStoneView;

import ee.rsi2m.goproject.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.SharedPreferences;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.Window;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class GameActivity extends Activity {
	public GoBoardView goBoardView;
	
	double [] settingsArray;
	
    /** Called when the activity is first created. */
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
    	
    	super.onCreate(savedInstanceState);
    	
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        Bundle bundle = getIntent().getExtras();
        settingsArray=bundle.getDoubleArray("settingsArray");
        
        
        
		MenuActivity.playGTP("boardsize "+(int)settingsArray[0]);
		MenuActivity.playGTP("komi " + settingsArray[3]);
		MenuActivity.playGTP("fixed_handicap " + settingsArray[1]);
		MenuActivity.playGTP("level 1");
        
        //goBoardView = new GoBoardView(this,width,height,(int)settingsArray[0], (int)settingsArray[1]);
        RelativeLayout relativeLayout = new RelativeLayout(this);
        
        /*
        Button i = new Button(this);
        i.setBackgroundResource(R.drawable.fivepfive);
        //i.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
        i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
        LayoutParams.WRAP_CONTENT));

        // Add the ImageView to the layout and set the layout as the content view

        relativeLayout.addView(goBoardView);
        relativeLayout.addView(i);*/
        setContentView(R.layout.game);
        
        /*ImageButton imageButton = (ImageButton) findViewById(R.id.finishMove);
        imageButton.setPressed(true);
        
        Log.w("button",(imageButton==null)+"");*/
    }
    
    @Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		return super.onTouchEvent(event);
	}

	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.optionsmenu, menu);
	    return true;
	}
	
	
    
    @Override
	protected void onRestart() {
    	GoBoardView gbv = (GoBoardView) findViewById(R.id.goboardview);
    	gbv.reloadGame();
		super.onRestart();
	}
    
    

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}

	public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case R.id.undo:
        	GoBoardView gbv = (GoBoardView) findViewById(R.id.goboardview);
        	gbv.onOptionsItemSelected(item);
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

	@Override
	protected Dialog onCreateDialog(int id) {
		// TODO Auto-generated method stub
		return super.onCreateDialog(id);
	}

	@Override
	protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
		// TODO Auto-generated method stub
		super.onPrepareDialog(id, dialog, args);
	}
}